package com.tenement.controller;

import com.tenement.common.Axios;
import com.tenement.entity.House;
import com.tenement.enums.RespBusiness;
import com.tenement.service.HouseService;
import com.tenement.vo.QueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  控制层。
 *
 * @author BertXie
 * @since 1.0.1
 */
@RestController
@RequestMapping("/house")
@RequiredArgsConstructor
@Api(tags = "房屋API")
public class HouseController {

    private final HouseService houseService;

    @ApiOperation("获取房屋的列表")
    @PostMapping("list")
    public Axios list(@RequestBody QueryVo queryVo) {
        return Axios.success(houseService.list(queryVo));
    }

    @ApiOperation("操作房屋数据")
    @PutMapping("operator")
    public Axios operator(@RequestBody House house) {
        return houseService.saveOrUpdate(house) ? Axios.success(RespBusiness.SUCCESS) : Axios.error(RespBusiness.FAIL);
    }

    @ApiOperation("删除房屋数据")
    @DeleteMapping("remove")
    public Axios remove(@RequestBody List<Long> ids) {
        return houseService.remove(ids) > 0 ? Axios.success(RespBusiness.SUCCESS) : Axios.error(RespBusiness.FAIL);
    }

    @ApiOperation("获取房屋状态的饼图数据")
    @GetMapping("statusPieChart")
    public Axios statusPieChart() {
        return Axios.success(houseService.statusPieChart());
    }

}
